package com.walkline.smzdm.dao;

import java.util.Vector;
import org.json.me.JSONArray;
import org.json.me.JSONException;
import org.json.me.JSONObject;
import com.walkline.smzdm.SMZDMSDK;
import com.walkline.smzdm.SMZDMException;
import com.walkline.smzdm.inf.Experience;
import com.walkline.smzdm.inf.ExperienceList;
import com.walkline.util.Function;

public class SMZDMExperienceList extends SMZDMObject implements ExperienceList
{
	private int _error = 0;
	private int _total_num = 0;
	private Vector _data = new Vector();

	public SMZDMExperienceList(SMZDMSDK smzdm, JSONObject jsonObject) throws SMZDMException
	{
		super(smzdm, jsonObject);

		JSONObject experienceList = jsonObject;
		if (experienceList != null)
		{
			_error = experienceList.optInt("error");
			_total_num = experienceList.optInt("totalnum");

			JSONArray experiencesArray = experienceList.optJSONArray("data");
			if (experiencesArray != null)
			{
				JSONObject experienceObject;
				for (int i=0; i<experiencesArray.length(); i++)
				{
					try {
						experienceObject = (JSONObject) experiencesArray.get(i);

						Experience experience = new SMZDMExperience(smzdm, experienceObject);
						if (experience != null) {_data.addElement(experience);}
					} catch (JSONException e) {Function.errorDialog(e.toString());}
				}
			}
		}
	}

	public int getError() {return _error;}

	public int getTotalNum() {return _total_num;}

	public Vector getExperience() {return _data;}
}